#include "Dinosaur.h"
#include "Point.h"
#include <string>
#include <iostream>
#include <fstream>
using namespace std;
Dinosaur::Dinosaur()
{
	//default constructor
	hasEgg=false;
	inBattle=false;
	reproductionLevel=0;
	hunger=100;
	flee=false;
}
void Dinosaur::hatch(string spec, bool carn, int att, int spe, int def, int health, int hd, int rr, int xpos, int ypos, int newID)
{
	hasEgg=false;
	inBattle=false;
	reproductionLevel=0;
	hunger=100;
	Species=spec;
	isCarn=carn;
	attack=att;
	speed=spe;
	defense=def;
	maxhealth=health;
	curhealth=maxhealth;
	hungerDepletion=hd;
	reproductionRate=rr;
	Location.Update(xpos, ypos);
	ID=newID;
	age=0;
}

int Dinosaur::getAge()
{
	return age;
}

string Dinosaur::getSpecies()
{
	return Species;
}

Point Dinosaur::getLocation()
{
	return Location;
}
int Dinosaur::getID()
{
	return ID;
}
int Dinosaur::getHunger()
{
	return hunger;
}
int Dinosaur::getAttack()
{
	return attack;
}
int Dinosaur::getDefense()
{
	return defense;
}
int Dinosaur::getSpeed()
{
	return speed;
}
int Dinosaur::getReproductionRate()
{
	return reproductionRate;
}
int Dinosaur::getHungerDepletion()
{
	return hungerDepletion;
}
bool Dinosaur::getCarn()
{
	return isCarn;
}
int Dinosaur::getCurHealth()
{
	return curhealth;
}
int Dinosaur::getMaxHealth()
{
	return maxhealth;
}
bool Dinosaur::getFlee()
{
	return flee;
}
void Dinosaur::getInfo()
{
	cout<<"My species is "<<Species<<endl;
	cout<<"My ID is "<<ID<<endl;
	cout<<"My Carn type is "<<boolalpha<<isCarn<<endl;
	cout<<"My attack is "<<attack<<endl;
	cout<<"My speed is "<<speed<<endl;
	cout<<"My defense is "<<defense<<endl;
	cout<<"My health is "<<maxhealth<<endl;
	cout<<"My hunger depletion is "<<hungerDepletion<<endl;
	cout<<"My reproduction rate is "<<reproductionRate<<endl;
	cout<<"My position is "<<Location.getX()<<" "<<Location.getY()<<endl;
}
string Dinosaur::getBehavior()
{
	return behavior;
}
bool Dinosaur::getInBattle()
{
	return inBattle;
}
void Dinosaur::setInBattle(bool bat)
{
	inBattle=bat;
}
void Dinosaur::setBehavior(string Beh)
{
	behavior=Beh;
}
void Dinosaur::setFlee(bool isflee)
{
	flee=isflee;
}
void Dinosaur::setHasEgg(bool has)
{
	hasEgg=has;
}
void Dinosaur::setAge()
{
	age++;
}

void Dinosaur::setLocation(Point newLoc)
{
	Location = newLoc;
}

void Dinosaur::layEgg()
{
	//add an egg to the list in command
}

void Dinosaur::eat()
{
	hunger+=30;
}

void Dinosaur::fight()
{
	//get closest dino from command
	//send both dinos to battle via command?
}

void Dinosaur::defend()
{
	//defend right after laying an egg
	//move to top of priority
}
void Dinosaur::Extract(ifstream& infile)
{
	char type;
	int x,y;
	infile>>Species;
	infile>>type;
	if(type=='c')
		isCarn=true;
	else
		isCarn=false;
	infile>>attack;
	infile>>speed;
	infile>>defense;
	infile>>maxhealth;
	curhealth=maxhealth;
	infile>>hungerDepletion;
	infile>>reproductionRate;
	infile>>x;
	infile>>y;
	Location.Update(x,y);

}
void Dinosaur::setID(int id)
{
	ID=id;
}
void Dinosaur::setCurHealth(int health)
{
	curhealth=health;
}
void Dinosaur::determineBehavior()
{
	if(inBattle)
	{
		behavior= "battle";
		return;
	}
	hunger=hunger-hungerDepletion;
	if(hunger<0)
		hunger=0;
	//dinosaur is starving
	if(hunger==0)
		curhealth=curhealth-(maxhealth/10);
	if(curhealth<=0)
	{
		behavior="death";
		return;
	}
	if(curhealth<maxhealth)
		curhealth++;
	if(hasEgg&&hunger>hungerDepletion*2)
	{
		behavior= "guard";
		return;
	}
	if(hunger<60)
	{
		behavior ="eat";
		if(hunger==0)
			behavior="starving";
		return;
	}
	if(reproductionLevel>reproductionRate)
	{
		behavior =  "lay";
		return;
	}
	reproductionLevel++;
	behavior= "wander";
}